var a = getApp();
Page({
    data: {
        selected: 0,
        list: ['待完成', '待审核', '已完成', '已驳回', '已过期'],
        items: [],
        orderList: {},

    },
    onShow() {
        this.getData()
        // this.otherList()
    },
    confirmReceipt(e) {
        console.log(e.currentTarget.dataset.value, '嗨嗨嗨')
        let quest_id = e.currentTarget.dataset.value.quest_info.id
        let draw_id = e.currentTarget.dataset.value.id
        let name = e.currentTarget.dataset.value.quest_info.name
        console.log(quest_id, draw_id)
        wx.navigateTo({
            url: '/packageJ/confirmReceipt/confirmReceipt?quest_id=' + quest_id + '&draw_id=' + draw_id + '&name=' + name,
        })
    },
    CancelTask(e) {
        let draw_id = e.currentTarget.dataset.value.id
        var t = this, e = a.getNetAddresss("plugin.task-reward.api.quest.cancel");
        a._getNetWork({
            url: e,
            data: {
                draw_id: draw_id,
            },
            success: function (a) {
                console.log(a.data, '有没有啊啊啊啊')
                wx.showToast({
                    title: a.data.msg,
                })
                t.getData()
            }
        });
    },
    reUpload(e) {
        let draw_id = e.currentTarget.dataset.value.id
        let name = e.currentTarget.dataset.value.quest_info.name
        wx.navigateTo({
            url: '/packageJ/reUpload/reUpload?draw_id=' + draw_id + '&name=' + name,
        })
    },
    uploadTask(e) {
        console.log(e.currentTarget.dataset.value.quest_info.name, '嗨嗨嗨')
        let quest_id = e.currentTarget.dataset.value.quest_info.id
        let draw_id = e.currentTarget.dataset.value.id
        let name = e.currentTarget.dataset.value.quest_info.name
        console.log(quest_id, draw_id)
        wx.navigateTo({
            url: '/packageJ/submitTask/submitTask?quest_id=' + quest_id + '&draw_id=' + draw_id + '&name=' + name,
        })
    },
    onLoad() {
        this.getData()
    },
    otherList() {
        var t = this, e = a.getNetAddresss("plugin.task-reward.api.quest.userQuest");
        a._getNetWork({
            url: e,
            data: {
                status: t.data.selected,
            },
            success: function (a) {
                console.log(a.data.data.data, '打印123')
                t.setData({
                    items: a.data.data.data
                })
            }
        });
    },
    getData() {
        var t = this, e = a.getNetAddresss("plugin.task-reward.api.quest.drawList");
        a._getNetWork({
            url: e,
            data: {
                status: '',
            },
            success: function (a) {
                console.log(a.data.data.data, '打印123')
                let arr = a.data.data.data
                let list = arr.map((item) => {
                    return {
                        ...item,
                        time_cha: item.end * 1000 - Date.parse(new Date())
                    }
                })
                console.log(list, '打印')
                t.setData({
                    items: list,
                })
            }
        });
    },
    //tab框
    selected: function (e) {
        let that = this
        console.log(e)
        let index = e.currentTarget.dataset.index
        console.log("index", index)
        if (index == 0) {
            that.setData({
                selected: ''
            })
            this.getData()
        } else if (index == 1) {
            that.setData({
                selected: 1
            })
            this.otherList()
        } else if (index == 2) {
            that.setData({
                selected: 2
            })
            this.otherList()
        } else if (index == 3) {
            that.setData({
                selected: 3
            })
            this.otherList()
        } else if (index == 4) {
            that.setData({
                selected: 4
            })
            this.otherList()
        }
    }
})